/*
 *    Copyright (c) 2018-2025, proj All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the proj developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: proj
 */

package com.ykht.proj.coupon.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ykht.proj.common.core.util.R;
import com.ykht.proj.common.log.annotation.SysLog;
import com.ykht.proj.common.security.util.SecurityUtils;
import com.ykht.proj.coupon.entity.FxWeight;
import com.ykht.proj.coupon.service.FxWeightService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * 权重表
 *
 * @author proj code generator
 * @date 2021-04-25 18:47:54
 */
@RestController
@AllArgsConstructor
@RequestMapping("/fxweight" )
@Api(value = "fxweight", tags = "权重表管理")
public class FxWeightController {

    private final  FxWeightService fxWeightService;

	@ApiOperation(value = "吃货攻略-推荐权重计算规则保存", notes = "吃货攻略-推荐权重计算规则")
    @PostMapping("updateBatch")
    public R updateBatch(@RequestBody List<FxWeight> list) {
    	list.stream().forEach(w->{
    		w.setUpdateTime(LocalDateTime.now());
    		w.setUpdateUser(SecurityUtils.getUserId());
		});
        return R.ok(fxWeightService.updateBatchById(list));
    }

	@ApiOperation(value = "吃货攻略-推荐权重计算规则回显")
	@GetMapping("/list" )
	public R<List<FxWeight>> list() {
    	return R.ok(fxWeightService.list(Wrappers.lambdaQuery(FxWeight.class).eq(FxWeight::getStatus,0).orderByAsc(FxWeight::getSort)));
	}

}
